import React from 'react'
import { HashRouter,Route,Switch,Redirect } from 'react-router-dom'
import Login from '../views/login/Login.jsx'
import Detail from '../views/news/Detail.jsx'
import News from '../views/news/News.jsx'
import NewsSandBox from '../views/sandbox/NewsSandBox.jsx'
export default function indexRouter() {
  return (
    <HashRouter>
      <Switch>
        
        <Route path="/login" component={Login}/>
        <Route path="/news" component={News}/>
        <Route path="/detail/:id" component={Detail}/>
        {/* <Route path="/" component={NewsSandBox} /> */}
        {/* 重定向,通过render形式再用三目表达式实现重定向 */}
        <Route path="/" render={()=>
        localStorage.getItem('token')?
         <NewsSandBox></NewsSandBox>:
         <Redirect to="/login"/>
        } />
      </Switch>
    </HashRouter>
  )
}
